package db.migrations;

import static com.eroi.migrate.Define.autoincrement;
import static com.eroi.migrate.Define.column;
import static com.eroi.migrate.Define.defaultValue;
import static com.eroi.migrate.Define.length;
import static com.eroi.migrate.Define.notnull;
import static com.eroi.migrate.Define.primarykey;
import static com.eroi.migrate.Define.table;
import static com.eroi.migrate.Define.uniqueIndex;
import static com.eroi.migrate.Define.DataTypes.BOOLEAN;
import static com.eroi.migrate.Define.DataTypes.INTEGER;
import static com.eroi.migrate.Define.DataTypes.LONGVARCHAR;
import static com.eroi.migrate.Define.DataTypes.NUMERIC;
import static com.eroi.migrate.Define.DataTypes.TIMESTAMP;
import static com.eroi.migrate.Define.DataTypes.TINYINT;
import static com.eroi.migrate.Define.DataTypes.VARCHAR;
import static com.eroi.migrate.Execute.addIndex;
import static com.eroi.migrate.Execute.createTable;
import static com.eroi.migrate.Execute.dropIndex;
import static com.eroi.migrate.Execute.dropTable;

import org.apache.log4j.Logger;

import com.eroi.migrate.Define.Length;
import com.eroi.migrate.Define.PrimaryKey;
import com.eroi.migrate.Migration;
import com.eroi.migrate.mchema.Column;

/**
 * 
 * Person
 * @author gongfu
 *
 */
public class Migration_2 implements Migration{

	private static final Logger logger  = Logger.getLogger(Migration_2.class);
	
	private final String T_B = "blog";
	private final String T_B_C = "blog_comment";
	
	public void up(){
		logger.info("Migration_2_blog.up--------------------->");
		createTable(
				table(T_B,
						column("id", INTEGER, "", primarykey(), notnull(), autoincrement()),
						column("pb_id", INTEGER, "", notnull()),
						column("sort_id", INTEGER, "", notnull()),
						column("title", VARCHAR, "标题", length(40), notnull()),
						column("content", LONGVARCHAR, "博客内容"),
						column("keyword", VARCHAR, "关键字", length(60)), 
						column("order_by", INTEGER, "序号", defaultValue(0)),
						column("post_time", TIMESTAMP, "发表博客时间"),
						column("readed_num", INTEGER, "被阅读次数", defaultValue(0)),
						column("commed_num", INTEGER, "被评论次数", defaultValue(0)),
						column("recommed_num", INTEGER, "被推荐次数", defaultValue(0)),
						column("favorited_num", INTEGER, "被收藏次数", defaultValue(0)),
						column("commed_able", TINYINT, "是否可评论0-不可;1-可", defaultValue(1)),
						column("is_able", TINYINT, "是否被和谐0-不可显示;1-可显示", defaultValue(1)),
						column("close_reson", VARCHAR, "和谐原因", length(40))
				)
		);
		
		createTable(
				table(T_B_C, 
						column("id", INTEGER, "", primarykey(), notnull(), autoincrement()),
						column("blog_id", INTEGER, "blog_id", notnull()),
						column("pid", INTEGER, "父级id", notnull()),
						column("pb_id", INTEGER, "与人关联", notnull()),
						column("content", LONGVARCHAR, "评论内容"),
						column("comm_time", TIMESTAMP, "评论时间")
					)
		);
	}
	
	public void down(){
		logger.info("Migration_2_blog.down--------------------->");
		dropTable(T_B);
		dropTable(T_B_C);
	}
}
